import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useAdminStore = defineStore('adminStore', () => {
  const adminame = ref<string>(localStorage.getItem('adminname') || '')
  const token = ref<string>(localStorage.getItem('token') || '')
  const role = ref<number>(Number(localStorage.getItem('role')) || 0)
  const checkedkeys = ref<any>(JSON.parse(localStorage.getItem('checkedkeys')!) || [])

  const changeAdminname = (params: string) => {
    adminame.value = params
    localStorage.setItem('adminname', params)
  }

  const changeToken = (params: string) => {
    token.value = params
    localStorage.setItem('token', params)
  }

  const changeRole = (params: number) => {
    role.value = params
    localStorage.setItem('role', params.toString(params))
  }

  const changeCheckedkeys = (params: string) => {
    checkedkeys.value = params
    localStorage.setItem('checkenkeys', JSON.stringify(params))
  }

  return {
    adminame,
    token,
    role,
    checkedkeys,
    changeAdminname,
    changeToken,
    changeRole,
    changeCheckedkeys
  }
})
